<template>
	<view>
		<uni-card padding="0" class="card-item" :border="false" shadow="0px 0px 10px 0px rgba(0, 0, 0, 0.08)" v-for="(item,index) in messageList" :key="index">
			<uni-list :border="false">
				<uni-list-chat avatar-circle :avatar="item.expertFace">
					<template v-slot:header>
						<view class="chat-custom-body" @click="goChat(item)">
							<view class="chat-custom-body-title"> {{ item.expertName }} <!-- <view class="title-tip">主任医师</view> -->
							</view>
							<view class="chat-custom-body-message" v-if="type == 1">您询问的问题</view>
							<view class="chat-custom-body-message" v-if="type == 2">回复了您的问题</view>
						</view>
					</template>
					<view class="chat-custom-right" @click="goChat(item)">
						<!-- <text class="chat-custom-text">45分钟前</text> -->
						<text class="chat-custom-tip">查看》</text>
					</view>
				</uni-list-chat>
			</uni-list>
		</uni-card>
	</view>
</template>

<script>
	import * as message from '../../common/api/message.js'
	export default {
		data() {
			return {
				dataList:[],
				messageList:[],
			}
		},
		methods: {
			queryMessage(){
				if(uni.getStorageSync('openid_key') != ''){
					const param = {
						memberId:uni.getStorageSync('openid_key')
					}
					message.queryMessage(param).then(res => {
						this.dataList = res.data.data.rows;
						let list = {};
            if(res.data.data.rows && res.data.data.rows.length>0){
              res.data.data.rows.forEach(item => {
              	if(item.expertFace == null){
              		item.expertFace = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0';
              	}
              	list[item.expertName] = item
              })
            }
						
						this.messageList = Object.values(list);
					})
				}
			},
      
      //进入咨询页面
      goChat(e){
            getApp().globalData.expertInfo=e;
            uni.navigateTo({
              url: "/pages/chat/chat"
            })
      },
      
			skip(name){
				let data = [];
				this.dataList.forEach(item =>{
					if(name == item.expertName){
						data.push(item);
					}					
				})
				uni.navigateTo({
					url:`/pages/message/detail?str=${JSON.stringify(data)}`
				});
			}
		},
		onShow() {
			this.queryMessage()
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: white;
	}

	.card-item {
		border-radius: 20rpx;
	}

	.chat-custom-body {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 10rpx;

		.chat-custom-body-title {
			color: #666666;
			font-weight: bold;
			font-size: 28rpx;
			display: flex;
		}

		.title-tip {
			font-size: 22rpx;
			color: white;
			background: #76C9B3;
			margin-left: 70rpx;
			padding-left: 10rpx;
			padding-right: 10rpx;
			border-radius: 8rpx;
			font-weight: bold;
		}

		.chat-custom-body-message {
			color: #999999;
			font-size: 24rpx;
		}
	}

	.chat-custom-right {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;

		.chat-custom-text {
			font-size: 22rpx;
			color: #999999;
		}

		.chat-custom-tip {
			font-size: 24rpx;
			color: #ccc;
		}
	}
</style>